<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function* generator(){
            console.log('开始获取a数据');
            yield setTimeout(()=>{
                        console.log('获取a数据成功');
                        //每次状态完成的时候调用下一次next
                        p1.next()
                    },1000)


                    console.log('开始获取b数据');
            yield setTimeout(()=>{
                        console.log('获取b数据成功');
                        
                        p1.next()
                    },1000)

                    console.log('开始获取c数据');
            yield setTimeout(()=>{
                        console.log('获取c数据成功');
                    },1000)
        }
        // 创建状态机后  ,不使用.next不运行
        const p1 = generator();
        p1.next();
        
    </script>
</body>
</html>